package com.ruoyi.framework.interceptor.impl;

import com.ruoyi.common.annotation.CheckUserId;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.framework.interceptor.CheckInterceptor;
import com.ruoyi.framework.web.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 检测 验证是否当前token中是否包含有效userid
 */
@Component
@Slf4j
public class CheckUserIdInterceptor extends CheckInterceptor {
    @Autowired
    private TokenService tokenService;
    @SuppressWarnings("unchecked")
    @Override
    public boolean isCheckUserId(HttpServletRequest request, CheckUserId annotation) {
        Long userId = tokenService.getUserId(request);
        if(userId==null) {
            log.info("进入CheckInterceptor:  无效userId");
            return true;
        }
        return false;
    }
}
